<?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller {
	/**
     * 自动执行
     */
    public function _initialize()
    {

    }

    //检测是否登录
    public function checkLogin(){
    	if(session('nickname') && session('37degree_tag')){
    		if(session('37degree_tag')===base64_encode(C('37DEGREE_HOME_TAG')."-".session('nickname'))){

    		}else{
    			//未登录
    			// $this->error('对不起,您还没有登录,正跳转至登录面...', U('Member/login'));
    		}
    	}
    }

	public function uploadfiy(){
		//上传文件，返回数据待定.....................
		$verifyToken = md5('unique_salt' . $_POST['timestamp']);
		if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
			$upload = new \Think\Upload();// 实例化上传类
		    $upload->maxSize   =     3145728 ;// 设置附件上传大小
		    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		    $upload->rootPath  =     APP_PATH.'/../Public/images/Uploads/'; // 设置附件上传根目录
		    $upload->savePath  =     ''; // 设置附件上传（子）目录
		    
		    $upload->autoSub = true;//
		    $upload->subName = array('date', 'Ymd');

		    // 上传文件 
		    $info   =   $upload->upload();
		    if(!$info) {// 上传错误提示错误信息
		        $this->error($upload->getError());
		    }else{// 上传成功
		        $this->success('上传成功！',$info);
		    }

		}
		
		// Define a destination
		$targetFolder = '/uploads'; // Relative to the root

		$verifyToken = md5('unique_salt' . $_POST['timestamp']);

		if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
			$tempFile = $_FILES['Filedata']['tmp_name'];
			$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
			$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
			
			// Validate the file type
			$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
			$fileParts = pathinfo($_FILES['Filedata']['name']);
			
			if (in_array($fileParts['extension'],$fileTypes)) {
				move_uploaded_file($tempFile,$targetFile);
				echo '1';
			} else {
				echo 'Invalid file type.';
			}
		}
	}



}